feat(realtime): scale uplink maxBitrate with publish fps below 15 fps - #192
Open
eilon-decart wants to merge 1 commit into
Open
feat(realtime): scale uplink maxBitrate with publish fps below 15 fps#192eilon-decart wants to merge 1 commit into
eilon-decart wants to merge 1 commit into
Conversation
The encoder spends its per-second bitrate budget regardless of cadence, so a 10 fps publisher packs ~3x the bytes into every frame; the oversized frames' wire-arrival span inflates the server's ingest jitter buffer by ~35-100 ms. Scaling the cap to ~200 kbit/frame below 15 fps restores 30 fps-parity ingest latency at equal-or-better QP (measured: 10 fps ingest hold 129.7 -> 28.4 ms, e2e 660 -> 557 ms from us-east4; full causal A/B in the api repo, experiments/2026-07-28-livekit-size-vs-interval-jb). No-op for every registry model today (all declare 30 fps) and for >=15 fps publishers; react-native path unchanged (no publishFps -> natural rate).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
getDefaultVideoPublishOptionsderives the uplinkmaxBitratefrom the intended publish fps instead of using the static 3.5M cap, engaging only below 15 fps:The fps is threaded from
prepareBrowserConnection(which already receivesresolveFpsNumber(model.fps)for the mirror canvas) into the media-channel factory. React-native path unchanged (nopublishFps→ natural rate).Why
Chrome's encoder spends its per-second budget regardless of cadence, so a 10 fps publisher packs ~3× the bytes into every frame (44KB vs 14KB). Those frames' wire-arrival span inflates the server's ingest jitter buffer — measured +98ms at 10 fps on a clean path. Scaling to ~200kbit/frame restores full 30 fps-parity:
Full causal A/B (19 sessions, size vs interval decomposition, dose–response, both IL and us-east4 clients):
DecartAI/api→experiments/2026-07-28-livekit-size-vs-interval-jb/(brancheilon/feature/lk-input-latency).Guardrail evidence baked into the constants: at ≥15 fps a binding cap measurably hurts (rate-controller churn, +32ms), and very low caps hit the simulcast layer-starvation cliff — hence the 15 fps threshold and the 1M floor.
Tests
tests/publish-options.unit.test.ts— 6 new unit tests (threshold, scaling, floor, natural-rate ceiling, omitted-fps fallback), all green.pnpm typecheck/ suite: the pre-existingframe-metadata-diagnostics.tstypecheck error and the mswunit.test.tsenv failure exist identically onorigin/main— not introduced here (verified via stash A/B).Follow-up (separate PR)
This covers declared low-fps models. Users whose camera actually delivers <15 fps while the model declares 30 need the measured-fps adaptive loop (
sender.getStats()→ livesetParametersre-apply with hysteresis) — mechanism already validated by the probe's cap loop.Linear (Platform team): PLA-660
Note
Medium Risk
Touches realtime uplink encoding for all browser sessions where fps is passed, but the scaling gate limits behavior change to declared fps below 15 fps; default registry paths remain unchanged.
Overview
Low-fps models now get a dynamic uplink
maxBitrateinstead of the fixed 3.5M cap.getDefaultVideoPublishOptionsscales toward ~200 kbit/frame when declared publish fps is below 15, with a 1M floor and the existing codec ceiling; at ≥15 fps or when fps is omitted, behavior stays byte-identical to today.Browser setup passes the model’s intended
publishFpsfromprepareBrowserConnectionintocreateLiveKitMediaChannel, so LiveKit publish options reflect declared cadence. NewREALTIME_CONFIG.livekitknobs document the threshold and scaling constants.Tests:
publish-options.unit.test.tscovers threshold, scaling, floor, ceiling, and omitted-fps fallback.Reviewed by Cursor Bugbot for commit 87b18b6. Bugbot is set up for automated code reviews on this repo. Configure here.